/*
 * Copyright (c) 2024 iSOFT INFRASTRUCTURE SOFTWARE CO., LTD.
 * easyAda is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */

#include "uart_bst.h"

#define UART_TX  0
#define UART_RX  0
#define UART_LSR 5

#define UART_LSR_THRE 0x20 /* Transmit-hold-register empty */
#define UART_LSR_TEMT 0x40 /* Transmitter empty */
#define BOTH_EMPTY    (UART_LSR_TEMT | UART_LSR_THRE)

#define UART_REG(mmio, x) ((volatile uint32_t *)((mmio) + (x)))

void serial_putchar(const char c)
{
    volatile unsigned int *mmio = (void *)DEVICE_VBASE_UART;
    *UART_REG(mmio, UART_TX)    = (c & 0xff);
    while (!(*UART_REG(mmio, UART_LSR) & BOTH_EMPTY)) {
        ;
    }
}
